package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.DataDictionaryItem;
import cn.wolfcode.crm.query.DictionaryQueryObject;
import cn.wolfcode.crm.service.IDataDictionaryItemService;
import cn.wolfcode.crm.query.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("dataDictionaryItem")
public class DataDictionaryItemController {

    @Autowired
    private IDataDictionaryItemService dataDictionaryItemService;

    //页面数据
    @RequestMapping("query")
    @ResponseBody
    public List<DataDictionaryItem> query(DictionaryQueryObject qo){
        return dataDictionaryItemService.selectAll(qo);
    }


    //名称检验
    @RequestMapping("validateByName")
    @ResponseBody
    public Boolean validateByName(Long id, String name){
        return dataDictionaryItemService.selectByName(id,name);
    }

    //编辑
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JSONResult saveOrUpdate(DataDictionaryItem dataDictionaryItem){
        JSONResult result = new JSONResult();
        try{
            dataDictionaryItemService.saveOrUpdate(dataDictionaryItem);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
    //删除
    @RequestMapping("delete")
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            dataDictionaryItemService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

}
